<template>
  <div class="container-header">
    <!-- 左侧 -->
    <div class="header-left">
      <img class="left-img" src="@/assets/logo.png" />
      <div class="left-title">{{ title }}</div>
    </div>
    <!-- 中间目录 -->
    <div class="header-center">
      <div v-for="(item, index) in menuList" :class="['menu-list-item', curId == item.id ? 'active' : '']" :key="index"
        @click="changeMenu(item)">
        <span class="menu-title"> {{ item.label }} </span>
      </div>
    </div>
    <!-- 右侧部分 -->
    <div class="header-right">
      <div>
        标准时间:<span class="right-time">{{ time }}</span>
      </div>
      <div class="admin-span">
        <el-dropdown trigger="click">
          <span class="el-dropdown-link">
            <span class="iconfont icon-wang"></span>
            管理员
            <el-icon class="el-icon--right">
              <arrow-down />
            </el-icon>
          </span>
          <template #dropdown>
            <el-dropdown-menu>
              <span @click="personalCenter">
                <el-dropdown-item class="padding">个人中心</el-dropdown-item>
              </span>
              <span @click="goBackHome">
                <el-dropdown-item class="Center">退出</el-dropdown-item>
              </span>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </div>
  </div>
</template>
<script lang="ts">
import {
  reactive,
  onBeforeMount,
  onMounted,
  toRefs,
  getCurrentInstance
} from "vue";
import store from "@/store";

export default {
  props: {
    menuList: {
      type: Array,
      default() {
        return [];
      },
    },
    // 标题
    title: {
      type: String,
      default: "场景编辑器",
    },
    // 是否展示菜单
    showMenu: {
      type: Boolean,
      default: true,
    },
    // 是否可设置
    showConfig: {
      type: Boolean,
      default: true,
    },
  },
  setup(props, { emit }) {
    const {
      appContext: {
        config: { globalProperties },
      },
    } = getCurrentInstance() as any;
    const state = reactive({
      isFullscreen: true,
      time: "",
      date: "",
      curId: "",
      loginTitle: "admin",
      show: true,
    });
    onBeforeMount(() => {
      isTime();
    });
    onMounted(() => {
      let topMenu: any = localStorage.getItem("topMenu");
      if (topMenu) {
        state.curId = JSON.parse(topMenu).id;
      } else {
        // changeMenu(props.menuList[0]);
      }
    });
    // 跳转到主页
    const toHome = () => {
      // console.log("home");
      globalProperties.$router.push("/home");
    };
    const fullScreen = () => {
      if (state.isFullscreen) {
        globalProperties.$utils.screenFullEnter();
      } else {
        globalProperties.$utils.screenFullOut();
      }

      state.isFullscreen = !state.isFullscreen;
    };
    //去主页
    const goHome = () => {
      let urlAddress = `http://${window.location.host}/tj/admin/`;
      location.href = urlAddress;
      // this.$router.push("/");
    };
    // 计时器
    const isTime = () => {
      // let time = setInterval(() => {
      //   _this.time = _this.$utils.formatDate(new Date(), 2);
      // }, 1000);
      state.time = globalProperties.$utils.formatDate(new Date(), 2);
      state.date = globalProperties.$utils.formatDate(new Date(), 1);

      setInterval(() => {
        state.time = globalProperties.$utils.formatDate(new Date(), 2);
        state.date = globalProperties.$utils.formatDate(new Date(), 1);
      }, 1000);
      console.log(state.time);
    };
    const changeMenu = (item: any) => {
      // if (item.name == "QB数据服务") {
      //   window.open(this.iframeURL);
      //   return;
      // }
      // console.log(item,'item')
      emit("changeMenu", item);
      // globalProperties.$router.push({ path: item.path, query: {} });
      state.curId = item.id;
    };
    // 个人中心
    const personalCenter = () => {
      emit("personalCenter");
    };
    // 退出
    const goBackHome = () => {
      store.commit("REMOVE_INFO");
      globalProperties.$router.push("/login");
      emit("goBackHome");
    };
    return {
      ...toRefs(state),
      goHome,
      isTime,
      fullScreen,
      changeMenu,
      toHome,
      personalCenter,
      goBackHome,
    };
  },
};
</script>

<style scoped lang="less">
.active {
  // background: #0377a8;
  // border-radius: 32px;
  // padding: 5px 0;
  // border: 1px solid #0377A8;
}

.iconfont {
  color: #008fc9;
  font-size: 24px;
}

.container-header {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  height: 70px;
  align-items: center;
  color: @main-font-color;
  border-bottom: 1px solid @global-border-color;
  background-color: #000;
  display: flex;

  .header-left {
    width: 400px;
    height: 100%;
    font-size: 23px;
    display: flex;
    align-items: center;
    justify-content: space-around;
    box-sizing: border-box;
    padding: 0 30px;
    background-image: url("../assets/image/header_bg.png");
    // background-repeat: no-repeat;
    background-size: 100% 100%;
    background-position: center;

    .left-img {
      width: 30px;
    }
  }

  .header-center {
    width: 60%;
    height: 100%;
    display: flex;
    justify-content: space-around;

    .menu-list-item {
      font-size: 23px;
      background: linear-gradient(to bottom, white 40%, blue 80%);
      -webkit-text-fill-color: transparent;
      -webkit-background-clip: text;
      font-weight: 700;
    }
  }

  .header-right {
    width: 20%;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;

    .right-time {
      color: #008fc9;
      margin-left: 8px;
    }

    .admin-span {
      height: 100%;
      // width: 50%;
      display: flex;
      justify-content: center;
      align-items: center;
      margin-left: 15px;

      .title-style {
        padding-left: 5px;
      }

      .el-dropdown-link {
        height: 100%;
        display: flex;
        align-items: center;
        color: #fff;
      }

      .icon-wang {
        margin-right: 8px;
      }
    }

    :deep(.el-dropdown-menu) {
      // padding: 5px 20px;
      padding: 0;
    }
  }
}

.menu-list {
  align-items: center;
  justify-content: space-around;
  flex: 1;
  height: 100%;
  // justify-content: space-around;
  margin-left: 100px;

  &-item {
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    font-size: @header-item-size;
    cursor: pointer;
  }
}
</style>
